﻿namespace PhotobucketNet
{
    using System;
    using System.Xml;

    public class User
    {
        private PhotobucketNet.Album _album;
        private string _albumUrl;
        private const string _albumUrlXml = "descendant::album_url";
        private UserContactList _contacts;
        private MediaItemList _imageMediaList;
        private int _mediaCount;
        private const string _mediaCountXml = "descendant::total_pictures";
        private MediaItemList _mediaList;
        private MediaTagList _mediaTags;
        private int _megabytesAllowed;
        private const string _megabytesAllowedXml = "descendant::megabytes_allowed";
        private int _megabytesUsed;
        private const string _megabytesUsedXml = "descendant::megabytes_used";
        private ImageSize _preferredPictureSize;
        private const string _preferredPictureSizeXml = "descendant::preferred_picture_size";
        private bool _premium;
        private const string _premiumXml = "descendant::premium";
        private bool _publicAccess;
        private const string _publicAccessXml = "descendant::public";
        private PhotobucketNet.UploadOptions _uploadOptions;
        private string _username;
        private const string _usernameXml = "descendant::username";
        private PhotobucketNet.UserUrls _userUrls;
        private MediaItemList _videoMediaList;

        public User(string username)
        {
            this._mediaList = new MediaItemList();
            this._imageMediaList = new MediaItemList();
            this._videoMediaList = new MediaItemList();
            this._mediaTags = new MediaTagList();
            this._contacts = new UserContactList();
            this._username = string.Empty;
            this._albumUrl = string.Empty;
            this._publicAccess = true;
            this._mediaCount = -1;
            this._preferredPictureSize = ImageSize.S100x75;
            this._megabytesUsed = -1;
            this._megabytesAllowed = -1;
            this._username = username;
        }

        internal User(XmlDocument userXml)
        {
            this._mediaList = new MediaItemList();
            this._imageMediaList = new MediaItemList();
            this._videoMediaList = new MediaItemList();
            this._mediaTags = new MediaTagList();
            this._contacts = new UserContactList();
            this._username = string.Empty;
            this._albumUrl = string.Empty;
            this._publicAccess = true;
            this._mediaCount = -1;
            this._preferredPictureSize = ImageSize.S100x75;
            this._megabytesUsed = -1;
            this._megabytesAllowed = -1;
            XmlNode userNode = userXml.SelectSingleNode("descendant::content");
            this.ParseFromXmlNode(userNode);
        }

        internal static User CreateFromXmlDocument(XmlNode userNode)
        {
            User user = new User("username");
            user.ParseFromXmlNode(userNode);
            return user;
        }

        public override bool Equals(object obj)
        {
            User user = obj as User;
            return this.Username.Equals(user.Username);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        private void ParseFromXmlNode(XmlNode userNode)
        {
            XmlNode node = userNode.SelectSingleNode("descendant::username");
            this._username = node.InnerText;
            XmlNode node2 = userNode.SelectSingleNode("descendant::album_url");
            this._albumUrl = node2.InnerText;
            XmlNode node3 = userNode.SelectSingleNode("descendant::megabytes_used");
            this._megabytesUsed = Convert.ToInt32(node3.InnerText);
            XmlNode node4 = userNode.SelectSingleNode("descendant::megabytes_allowed");
            this._megabytesAllowed = Convert.ToInt32(node4.InnerText);
            XmlNode node5 = userNode.SelectSingleNode("descendant::premium");
            this._premium = Convert.ToBoolean(Convert.ToInt32(node5.InnerText));
            XmlNode node6 = userNode.SelectSingleNode("descendant::public");
            this._publicAccess = Convert.ToBoolean(Convert.ToInt32(node6.InnerText));
            XmlNode node7 = userNode.SelectSingleNode("descendant::total_pictures");
            this._mediaCount = Convert.ToInt32(node7.InnerText);
            XmlNode node8 = userNode.SelectSingleNode("descendant::preferred_picture_size");
            this._preferredPictureSize = PhotobucketImageSize.CreateFromString(node8.InnerText);
        }

        public PhotobucketNet.Album Album
        {
            get
            {
                return this._album;
            }
        }

        public string AlbumUrl
        {
            get
            {
                return this._albumUrl;
            }
        }

        public UserContactList Contacts
        {
            get
            {
                return this._contacts;
            }
        }

        public MediaItemList ImageMediaList
        {
            get
            {
                return this._imageMediaList;
            }
        }

        public int MediaCount
        {
            get
            {
                return this._mediaCount;
            }
        }

        public MediaItemList MediaList
        {
            get
            {
                return this._mediaList;
            }
        }

        public MediaTagList MediaTags
        {
            get
            {
                return this._mediaTags;
            }
        }

        public int MegabytesAllowed
        {
            get
            {
                return this._megabytesAllowed;
            }
        }

        public int MegabytesUsed
        {
            get
            {
                return this._megabytesUsed;
            }
        }

        public ImageSize PreferredPictureSize
        {
            get
            {
                return this._preferredPictureSize;
            }
        }

        public bool Premium
        {
            get
            {
                return this._premium;
            }
        }

        public bool PublicAccess
        {
            get
            {
                return this._publicAccess;
            }
        }

        internal PhotobucketNet.Album SetAlbum
        {
            set
            {
                this._album = value;
            }
        }

        internal UserContactList SetContact
        {
            set
            {
                this._contacts = value;
            }
        }

        internal MediaItemList SetImageMediaList
        {
            set
            {
                this._imageMediaList = value;
            }
        }

        internal MediaItemList SetMediaList
        {
            set
            {
                this._mediaList = value;
            }
        }

        internal MediaTagList SetMediaTags
        {
            set
            {
                this._mediaTags = value;
            }
        }

        internal PhotobucketNet.UploadOptions SetUploadOptions
        {
            set
            {
                this._uploadOptions = value;
            }
        }

        internal PhotobucketNet.UserUrls SetUserUrls
        {
            set
            {
                this._userUrls = value;
            }
        }

        internal MediaItemList SetVideoMediaList
        {
            set
            {
                this._videoMediaList = value;
            }
        }

        public PhotobucketNet.UploadOptions UploadOptions
        {
            get
            {
                return this._uploadOptions;
            }
        }

        public string Username
        {
            get
            {
                return this._username;
            }
        }

        public PhotobucketNet.UserUrls UserUrls
        {
            get
            {
                return this._userUrls;
            }
        }

        public MediaItemList VideoMediaList
        {
            get
            {
                return this._videoMediaList;
            }
        }
    }
}

